import type { RouteRecordRaw } from "vue-router";

export const DynamicRoutes: Array<RouteRecordRaw> = [
  {
    path: "/project",
    component: () => import("@/views/project/index.vue"),
    name: "Project",
    meta: { icon: "iconfont icon-xiangmuguanli", title: "项目管理", role: [1] },
  },
  {
    path: "/team",
    component: () => import("@/views/team/index.vue"),
    name: "Team",
    meta: { icon: "iconfont icon-tuanduiguanli", title: "分组管理", role: [1] },
  },
  {
    path: "/grade",
    component: () => import("@/views/grade/index.vue"),
    name: "Grade",
    meta: {
      icon: "iconfont icon-pingfenbiaozhun",
      title: "评分标准",
      role: [1],
    },
  },
  {
    path: "/teachers",
    component: () => import("@/views/teachers/index.vue"),
    name: "Teachers",
    meta: { icon: "iconfont icon-jiaoshi", title: "教师管理", role: [1] },
  },
  {
    path: "/students",
    component: () => import("@/views/students/index.vue"),
    name: "Students",
    meta: {
      icon: "iconfont icon-zuyuanguanli1",
      title: "学生管理",
      role: [1],
    },
  },
  {
    path: "/member",
    component: () => import("@/views/member/index.vue"),
    name: "Member",
    meta: {
      icon: "iconfont icon-zuyuanguanli1",
      title: " 组员管理",
      role: [2],
    },
  },
  {
    path: "/my-project",
    component: () => import("@/views/my-project/index.vue"),
    name: "MyProject",
    meta: {
      icon: "iconfont icon-xiangmu1",
      title: "我的项目",
      role: [2, 3],
    },
  },
  {
    path: "/file",
    component: () => import("@/views/file/index.vue"),
    name: "File",
    meta: {
      icon: "iconfont icon-fujian",
      title: "附件管理",
      role: [2, 3],
    },
  },
  // {
  //   path: "/user",
  //   component: () => import("@/views/user/index.vue"),
  //   name: "User",
  //   meta: { icon: "iconfont icon-zhanghaoguanli", title: " 用户管理", role: 1 },
  // },
];

export const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    name: "home",
    component: () => import("@/layout/index.vue"),
    redirect: () => {
      if (localStorage.getItem("roleId") === "1") {
        return "/project";
      } else if (localStorage.getItem("roleId") === "2") {
        return "/member";
      }
      return "/my-project";
    },
    children: DynamicRoutes,
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/login/index.vue"),
  },
  {
    path: "/:pathMatch(.*)",
    name: "404",
    component: () => import("@/views/ErrorView.vue"),
  },
];
